import { defineStore } from 'pinia'
// import { locGet, locSet } from '@/utils/common'
import type { State } from './types/nav'
import { menuArr } from '@/staticData/nav'

export const navStore = defineStore('navStore', {
  state: (): State => ({
    navKey: '',
    matched: [],
  }),
  actions: {
    setBreadcrumb(data: any[]) {
      this.matched = data
    },
  },
  getters: {
    curryNav: (state) => menuArr[state.navKey] ?? menuArr.dataManagement,
    breadcrumbData(state) {
      const len = state.matched.length - 1
      const breadcrumb = []
      for (const item of state.matched) {
        breadcrumb.push(item.meta.breadcrumb)
      }
      const result = {
        pageName: breadcrumb[len].name,
        breadcrumb,
      }
      return result
    },
  },
})
